import React from 'react';
import store from '../myRedux/store.js';
// import { ADD_NUM } from '../reducers/types.js'
import { addNum } from  '../actionsCreator/counter.js'

class Count extends React.Component {
    state = {
        data: store.getState().counter
    }
    add = () => {
        const action = addNum(3);
        store.dispatch(action)
    }
    componentDidMount () {
        store.subscribe(() => {
            this.setState({
                data: store.getState().counter
            })
        })
    }
    render () {
        const {num} = this.state.data
        return(
            <div>
                <p> { num } </p>
                <button onClick={ this.add }>++</button>
            </div>
            )
    }
}

export default Count;